package com.example.demo.controller;

import com.example.demo.model.MessageInfo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/message")
public class MessageController {
    //暂时将数据存储在内存中
    List<MessageInfo> messageInfoList = new ArrayList<>();
    @RequestMapping("/send")
    //获取数据
    public boolean send(MessageInfo messageInfo) {
        if(!StringUtils.hasLength(messageInfo.getMessage())
        || !StringUtils.hasLength(messageInfo.getFrom())
        || !StringUtils.hasLength(messageInfo.getTo())) {
            return false;
        }
        messageInfoList.add(messageInfo);
        return true;
    }
    //返回message
    @RequestMapping("/getMessage")
    public List<MessageInfo> getMessage() {
        return messageInfoList;
    }

}
